package com.sx.controller;


import com.sx.domain.PromotionSpace;
import com.sx.domain.ResponseResult;
import com.sx.service.PromotionSpaceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/promotionSpace")
public class PromotionSpaceController {

    @Autowired
    private PromotionSpaceService promotionSpaceService;
    @RequestMapping("/findAllPromotionSpace")
    public ResponseResult findAllPromotionSpace(){
        List<PromotionSpace> allPromotionSpace = promotionSpaceService.findAllPromotionSpace();
        return new ResponseResult(true,200,"响应成功",allPromotionSpace);
    }

    //添加广告位
    @RequestMapping("/saveOrUpdatePromotionSpace")
    public ResponseResult saveOrUpdatePromotionSpace(@RequestBody PromotionSpace promotionSpace){
        if (promotionSpace.getId()==null){
            promotionSpaceService.savePromotionSpace(promotionSpace);
            return new ResponseResult(true,200,"添加成功",null);
        }else {
            promotionSpaceService.updatePromotionSpace(promotionSpace);
            return new ResponseResult(true,200,"修改成功",null);
        }
    }

    //根据id查询广告位
    @RequestMapping("/findPromotionSpaceById")

    public ResponseResult findPromotionAdById(int id){
        PromotionSpace promotionSpaceId = promotionSpaceService.findPromotionSpaceId(id);
        ResponseResult result = new ResponseResult(true, 200, "响应成功", promotionSpaceId);
        return result;
    }
}